package com.example.aigc_education.service.converter;

import com.example.aigc_education.domain.Plan;
import com.example.aigc_education.domain.vo.ListPlanVO;
import com.example.aigc_education.domain.vo.PlanVO;
import com.example.aigc_education.enums.PlanPriorityType;
import org.mapstruct.*;

import java.util.List;

@Mapper(componentModel = "spring")
public interface PlanConverter {

    /**
     * plan --> planVO
     */
    PlanVO planToPlanVO(Plan plan);


    /**
     * Plan-->listPlanVO
     */
    @Mappings(
            value = {
                    @Mapping(source = "planName", target = "title"),
                    @Mapping(source = "completionProgress", target = "progress"),
                    @Mapping(target = "currentModule", ignore = true)
            }
    )
    ListPlanVO planToListPlanVO(Plan plan);

    //调用完自动转化后，会自动调用本方法
    @AfterMapping
    default void getPriorityTag(Plan plan, @MappingTarget ListPlanVO listPlanVO){
        Integer priorityValue = plan.getPriority();
        PlanPriorityType planPriorityType = PlanPriorityType.fromValue(priorityValue);
        listPlanVO.setPriorityTag(new ListPlanVO.PriorityTagVO(planPriorityType.getTitle(), planPriorityType.getColor()));
        listPlanVO.setCurrentModule(new ListPlanVO.CurrentModel(plan.getCurrentModule(), null,""));
    }

    List<ListPlanVO> plansToListPlanVOs(List<Plan> plans);


}
